package com.example.tellwin.mine.presenter;

import com.example.tellwin.AppHelper;
import com.example.tellwin.MainApplication;
import com.example.tellwin.api.TwjfApi;
import com.example.tellwin.base.RxPresenter;
import com.example.tellwin.base.SimpleCallback;
import com.example.tellwin.mine.bean.UserBean;
import com.example.tellwin.mine.contract.IdentitySelectContract;
import com.example.tellwin.utils.HttpUtils;

import javax.inject.Inject;

import okhttp3.RequestBody;

/**
 * @author : LinZePeng
 * @date : 2020/11/25
 * @Describe ：
 **/
public class IdentitySelectPresenter extends RxPresenter<IdentitySelectContract.View> implements IdentitySelectContract.Presenter<IdentitySelectContract.View> {
    private TwjfApi mApi;

    @Inject
    public IdentitySelectPresenter(TwjfApi mApi) {
        this.mApi = mApi;
    }


    @Override
    public void selectIdentity(String userIdentity) {
        RequestBody requestBody = HttpUtils.getRequestBody("userIdentity" , userIdentity);
        mApi.updateUserInfo(requestBody , new SimpleCallback<Object>(mView) {
            @Override
            public void onSuccess(Object o) {
                UserBean userBean = AppHelper.getInstance().getUser();
                userBean.setIsIdentity(1);
                AppHelper.getInstance().saveUser(userBean , MainApplication.getCurActivity());
                mView.selectIdentitySuccess();
            }

            @Override
            public void onFail(String msg) {

            }
        });
    }
}
